import { computed, type ComputedRef, toRefs } from "vue";
import { calcArrayExtremum } from "@/utils/common";

/**
 * @description:  计算 usl 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useUslMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const {
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  return computed(() => {
    const arr = [
      startValue.value,
      uclValue.value,
      uwlValue.value,
      u3lValue.value,
      targetValue.value,
      lwlValue.value,
      lclValue.value,
      lslValue.value,
      l3lValue.value
    ];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 ucl 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useUclMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const {
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, uwlValue.value, u3lValue.value, targetValue.value, lwlValue.value, lclValue.value, lslValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 uwl 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useUwlMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const {
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, u3lValue.value, targetValue.value, lwlValue.value, lclValue.value, lslValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 u3l 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useU3lMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const { targetValue = undefined, lwlValue = undefined, lclValue = undefined, lslValue = undefined, l3lValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, targetValue.value, lwlValue.value, lclValue.value, lslValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 target 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useTargetMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const { lwlValue = undefined, lclValue = undefined, lslValue = undefined, l3lValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, lwlValue.value, lclValue.value, lslValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 lwl 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useLwlMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const { lclValue = undefined, lslValue = undefined, l3lValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, lclValue.value, lslValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 lcl 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useLclMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const { lslValue = undefined, l3lValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, lslValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 lsl 最小值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useLslMin = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  const { l3lValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [startValue.value, l3lValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

/**
 * @description:  计算 l3l 最小值
 * @param {Record} baseInfoData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useL3lMin = (baseInfoData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { startValue = undefined } = toRefs(baseInfoData);
  return computed(() => {
    const arr = [startValue.value];
    return calcArrayExtremum(arr, 0, "max") as number | undefined | null;
  });
};

// ---------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------

/**
 * @description:  计算 usl 最大值
 * @return {ComputedRef<number|undefined|null>}
 */
export const useUslMax = (): ComputedRef<number | undefined | null> => {
  return computed(() => {
    const arr = [];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 ucl 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useUclMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { uslValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 uwl 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useUwlMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { uslValue = undefined, uclValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 u3l 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useU3lMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { uslValue = undefined, uclValue = undefined, uwlValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value, uwlValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 target 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useTargetMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { uslValue = undefined, uclValue = undefined, uwlValue = undefined, u3lValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value, uwlValue.value, u3lValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 lwl 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useLwlMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const { uslValue = undefined, uclValue = undefined, uwlValue = undefined, u3lValue = undefined, targetValue = undefined } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value, uwlValue.value, u3lValue.value, targetValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 lcl 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useLclMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined
  } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value, uwlValue.value, u3lValue.value, targetValue.value, lwlValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 lsl 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useLslMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined
  } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value, uwlValue.value, u3lValue.value, targetValue.value, lwlValue.value, lclValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

/**
 * @description:  计算 l3l 最大值
 * @param {Record} baseInfoData
 * @param {Record} limitData
 * @return {ComputedRef<number|undefined|null>}
 */
export const useL3lMax = (baseInfoData?: Record<string, any>, limitData?: Record<string, any>): ComputedRef<number | undefined | null> => {
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined
  } = toRefs(limitData);
  return computed(() => {
    const arr = [uslValue.value, uclValue.value, uwlValue.value, u3lValue.value, targetValue.value, lwlValue.value, lclValue.value, lslValue.value];
    return calcArrayExtremum(arr, Infinity, "min") as number | undefined | null;
  });
};

export const checkUslValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (uclValue.value && value < uclValue.value) {
    callback(new Error("USL值应该大于UCL值"));
  } else if (uwlValue.value && value < uwlValue.value) {
    callback(new Error("USL值应该大于UWL值"));
  } else if (u3lValue.value && value < u3lValue.value) {
    callback(new Error("USL值应该大于U3L值"));
  } else if (targetValue.value && value < targetValue.value) {
    callback(new Error("USL值应该大于Target值"));
  } else if (lwlValue.value && value < lwlValue.value) {
    callback(new Error("USL值应该大于LWL值"));
  } else if (lclValue.value && value < lclValue.value) {
    callback(new Error("USL值应该大于LCL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("USL值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("USL值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("USL值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkUclValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (uslValue.value && value > uslValue.value) {
    callback(new Error("UCL值应该小于USL值"));
  } else if (uwlValue.value && value < uwlValue.value) {
    callback(new Error("UCL值应该大于UWL值"));
  } else if (u3lValue.value && value < u3lValue.value) {
    callback(new Error("UCL值应该大于U3L值"));
  } else if (targetValue.value && value < targetValue.value) {
    callback(new Error("UCL值应该大于Target值"));
  } else if (lwlValue.value && value < lwlValue.value) {
    callback(new Error("UCL值应该大于LWL值"));
  } else if (lclValue.value && value < lclValue.value) {
    callback(new Error("UCL值应该大于LCL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("UCL值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("UCL值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("UCL值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkUwlValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (uclValue.value && value > uclValue.value) {
    callback(new Error("UWL值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("UWL值应该小于USL值"));
  } else if (u3lValue.value && value < u3lValue.value) {
    callback(new Error("UWL值应该大于U3L值"));
  } else if (targetValue.value && value < targetValue.value) {
    callback(new Error("UWL值应该大于Target值"));
  } else if (lwlValue.value && value < lwlValue.value) {
    callback(new Error("UWL值应该大于LWL值"));
  } else if (lclValue.value && value < lclValue.value) {
    callback(new Error("UWL值应该大于LCL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("UWL值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("UWL值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("UWL值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkU3lValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("U3L值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("U3L值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("U3L值应该小于USL值"));
  } else if (targetValue.value && value < targetValue.value) {
    callback(new Error("U3L值应该大于Target值"));
  } else if (lwlValue.value && value < lwlValue.value) {
    callback(new Error("U3L值应该大于LWL值"));
  } else if (lclValue.value && value < lclValue.value) {
    callback(new Error("U3L值应该大于LCL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("U3L值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("U3L值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("U3L值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkTargetValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (u3lValue.value && value > u3lValue.value) {
    callback(new Error("Target值应该小于U3L值"));
  } else if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("Target值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("Target值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("Target值应该小于USL值"));
  } else if (lwlValue.value && value < lwlValue.value) {
    callback(new Error("Target值应该大于LWL值"));
  } else if (lclValue.value && value < lclValue.value) {
    callback(new Error("Target值应该大于LCL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("Target值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("Target值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("Target值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkLwlValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (targetValue.value && value > targetValue.value) {
    callback(new Error("LWL值应该小于Target值"));
  } else if (u3lValue.value && value > u3lValue.value) {
    callback(new Error("LWL值应该小于U3L值"));
  } else if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("LWL值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("LWL值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("LWL值应该小于USL值"));
  } else if (lclValue.value && value < lclValue.value) {
    callback(new Error("LWL值应该大于LCL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("LWL值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("LWL值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("LWL值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkLclValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (lwlValue.value && value > lwlValue.value) {
    callback(new Error("LCL值应该小于LWL值"));
  } else if (targetValue.value && value > targetValue.value) {
    callback(new Error("LCL值应该小于Target值"));
  } else if (u3lValue.value && value > u3lValue.value) {
    callback(new Error("LCL值应该小于U3L值"));
  } else if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("LCL值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("LCL值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("LCL值应该小于USL值"));
  } else if (lslValue.value && value < lslValue.value) {
    callback(new Error("LCL值应该大于LSL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("LCL值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("LCL值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkLslValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (lclValue.value && value > lclValue.value) {
    callback(new Error("LSL值应该小于LCL值"));
  } else if (lwlValue.value && value > lwlValue.value) {
    callback(new Error("LSL值应该小于LWL值"));
  } else if (targetValue.value && value > targetValue.value) {
    callback(new Error("LSL值应该小于Target值"));
  } else if (u3lValue.value && value > u3lValue.value) {
    callback(new Error("LSL值应该小于U3L值"));
  } else if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("LSL值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("LSL值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("LSL值应该小于USL值"));
  } else if (l3lValue.value && value < l3lValue.value) {
    callback(new Error("LSL值应该大于L3L值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("LSL值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkL3lValue = (rule: any, value: any, callback: any, limitData?: Record<string, any>, baseInfoData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined
  } = toRefs(limitData);
  const { startValue = undefined } = toRefs(baseInfoData);
  if (lslValue.value && value > lslValue.value) {
    callback(new Error("L3L值应该小于LSL值"));
  } else if (lclValue.value && value > lclValue.value) {
    callback(new Error("L3L值应该小于LCL值"));
  } else if (lwlValue.value && value > lwlValue.value) {
    callback(new Error("L3L值应该小于LWL值"));
  } else if (targetValue.value && value > targetValue.value) {
    callback(new Error("L3L值应该小于Target值"));
  } else if (u3lValue.value && value > u3lValue.value) {
    callback(new Error("L3L值应该小于U3L值"));
  } else if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("L3L值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("L3L值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("L3L值应该小于USL值"));
  } else if (startValue.value && value < startValue.value) {
    callback(new Error("L3L值应该大于Y轴起始值"));
  } else {
    callback();
  }
};

export const checkStartValue = (rule: any, value: any, callback: any, baseInfoData?: Record<string, any>, limitData?: Record<string, any>) => {
  if (typeof value !== "number") return callback();
  const {
    uslValue = undefined,
    uclValue = undefined,
    uwlValue = undefined,
    u3lValue = undefined,
    targetValue = undefined,
    lwlValue = undefined,
    lclValue = undefined,
    lslValue = undefined,
    l3lValue = undefined
  } = toRefs(limitData);
  if (l3lValue.value && value > l3lValue.value) {
    callback(new Error("Y轴起始值应该小于L3L值"));
  } else if (lslValue.value && value > lslValue.value) {
    callback(new Error("Y轴起始值应该小于LSL值"));
  } else if (lclValue.value && value > lclValue.value) {
    callback(new Error("Y轴起始值应该小于LCL值"));
  } else if (lwlValue.value && value > lwlValue.value) {
    callback(new Error("Y轴起始值应该小于LWL值"));
  } else if (targetValue.value && value > targetValue.value) {
    callback(new Error("Y轴起始值应该小于Target值"));
  } else if (u3lValue.value && value > u3lValue.value) {
    callback(new Error("Y轴起始值应该小于U3L值"));
  } else if (uwlValue.value && value > uwlValue.value) {
    callback(new Error("Y轴起始值应该小于UWL值"));
  } else if (uclValue.value && value > uclValue.value) {
    callback(new Error("Y轴起始值应该小于UCL值"));
  } else if (uslValue.value && value > uslValue.value) {
    callback(new Error("Y轴起始值应该小于USL值"));
  } else {
    callback();
  }
};
